package cn.stronglink.asset.message.mq.consumer;

import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import cn.stronglink.asset.message.mq.consumer.entity.Reader003R;
import cn.stronglink.asset.message.mq.consumer.entity.Reader003Udev;
import cn.stronglink.asset.message.mq.consumer.jdEntity.BaseReceiver;
import cn.stronglink.asset.message.mq.consumer.jdEntity.LightSuccessData;
import cn.stronglink.asset.module.rfidState.service.RfidStateJdService;

public class JDThreadExcute {
	
	public static ExecutorService executorService = new ThreadPoolExecutor(100,200,10,TimeUnit.SECONDS,new ArrayBlockingQueue<Runnable>(5000));
	
	public JDThreadExcute(){}
	
}

class JdThread implements Runnable  {
	TextMessage tm ;
	RfidStateJdService rfidStateJdService;
	private static final Logger logger = LoggerFactory.getLogger(JdThread.class);

	public JdThread(TextMessage tm, RfidStateJdService rfidStateJdService) {
		this.tm=tm;
		this.rfidStateJdService=rfidStateJdService;
	}
	
	@Override
	public void run() {
		try {
			String msg= tm.getText();
			if(!"".equals(msg)&&!"null".equals(msg)&&msg!=null){
			    BaseReceiver bm = JSON.parseObject(msg, BaseReceiver.class);
				String rfidType = bm.getRfidtype();
				String actionCode = bm.getActioncode();
			   if("smarrack".equals(rfidType)) {
					if("reader003".equals(actionCode)){						
						logger.info("**********接收采集到的标签列表："+bm.getAwsPostdata().toString());
						
						Reader003R reader003 = JSONObject.parseObject(bm.getAwsPostdata().toString(), Reader003R.class);
						String cabinetCode = reader003.getDevAddrList().get(0).getDevAddrCode();// 机柜编号
						List<Reader003Udev> rfidAndUList = reader003.getDevAddrList().get(0).getUdevInfo();//采集过来的rfid和u位信息
						rfidStateJdService.updateUJingDong(cabinetCode,rfidAndUList); //京东
					}else if("reader605".equals(actionCode)){							
						LightSuccessData successData = JSONObject.parseObject(bm.getAwsPostdata().toString(), LightSuccessData.class);
						rfidStateJdService.doSuccess(successData,bm.getTimeStamp()); //京东
						
					}
				}
			}
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
